package 力扣._元辅音字符串计数1;

import java.util.Arrays;

class Solution {


    public int countOfSubstrings(String word, int k) {
        //双指针
        int[] count= new int[5];
        char[] yuans = new char[]{'a','e','i','o','u'};
        int ans=0;
        for(int p=0;p<word.length()-4;p++){
            int i=p,j=p;
            while (i<=j && j < word.length()){
                // 将j指向的加入当前窗口
                int i1 = Arrays.binarySearch(yuans, word.charAt(j));
                if(i1>=0){
                    count[i1] ++;
                }
                int y_sum = count[0]+count[1]+count[2]+count[3]+count[4];
                // 当前辅音数量
                int t = j-i+1 - y_sum;

                if(t<k)
                    j++;
                else if(t==k){
                    // 是否每一个元音都存在
                    boolean flag = true;
                    for (int yuan : count) {
                        if(yuan==0){
                            flag=false;
                            break;
                        }
                    }
                    if(flag){
                        System.out.println(word.substring(i,j+1));
                        ans++;
                    }
                    j++;

                }else{
                    // 将i从当前窗口中出去
                    i1 = Arrays.binarySearch(yuans, word.charAt(i));
                    if(i1>=0)
                        count[i1]--;
                    i+=1;

                }

            }
        }

        return  ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int count = solution.countOfSubstrings("iqeaouqi", 2);
        System.out.println(count);


    }
}